using UnityEngine;
using System.Collections;

public class BaseGrid : MonoBehaviour
{
	private static BaseGrid _SelfBaseGrid;

	public static BaseGrid SelfBaseGrid
	{
		get
		{
			return _SelfBaseGrid;
		}
		set
		{
			_SelfBaseGrid = value;
		}
	}

	public Vector2[][] gridArray;
	private int _coordWidth = 13;
	private int _coordHeight = 10;

	// Use this for initialization
	void Start ()
	{
		_SelfBaseGrid = this as BaseGrid;
		CreateGrid();
	}

	private float sizeOfCube = 1f;
	private void CreateGrid()
	{
		gridArray = new Vector2[13][];
		for (int i = 0; i < gridArray.Length; i++)
		{
			gridArray[i] = new Vector2[10];
			for (int j = 0; j < gridArray[i].Length; j++)
			{
				gridArray[i][j] = new Vector2((-0.5f * renderer.bounds.size.x) + (i * sizeOfCube), (-0.5f * renderer.bounds.size.y) + (j * sizeOfCube));
			}
		}
	}

	public Vector2 GetGridCoords(Vector3 inCubeLocation)
	{
		Vector2 returnVal = new Vector2(0,0);
		returnVal.x = renderer.bounds.size.x / gridArray.GetLength(0);

		return returnVal;
	}
	
	private void WhenDirectionChanges(Vector2 inNewDir)
	{
	}
	
	// Update is called once per frame
	void Update ()
	{
		
	}

	public Vector2 GetNextChangeDirPos(Vector3 location, Vector2 direction)
	{
		//should actally return the last grid location according to the location and direction of the cube.

		//temporary return
//		return new Vector2(0,0);

		Vector2 loc = GetGridCoords(location);

		if (direction.x > 0)
		{
			return gridArray[_coordWidth - 1][(int)loc.y];
		}
	}
}
